package com.example.lab3.api.controller.v1;

import com.example.lab3.api.dto.EmployeeDTO;
import com.example.lab3.domain.entity.Employee;
import com.example.lab3.service.EmployeeService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
@RequestMapping("/v1/page")
public class PageController {

    private final EmployeeService employeeService;

    public PageController(EmployeeService employeeService) {
        this.employeeService = employeeService;
    }

    @GetMapping("/list")
    public String list(Model model, EmployeeDTO employeeDTO) {
        List<Employee> employeeList = employeeService.listEmployees(employeeDTO);
        model.addAttribute("data", employeeList);
        model.addAttribute("title", "员工列表");
        // 返回thymeleaf对应的页面
        return "employee";
    }

}
